package user8086.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import user8086.entity.param.UserAddParam;
import user8086.entity.po.User;
import user8086.entity.param.UserLoginParam;
import user8086.mapper.UserMapper;
import user8086.service.UserService;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ttxxi
 * @since 2022-05-31
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public Long login(UserLoginParam param) {
        User user = userMapper.selectByUsernameAndPassword(param);
        if (user!=null){
            return user.getId();
        }else {
            return null;
        }

    }

    @Override
    public Boolean addUser(UserAddParam param) {
        User user = new User();
        user.setUsername(param.getUsername());
        user.setPassword(param.getPassword());
        int insert = userMapper.insert(user);
        return insert == 1;
    }
}
